package com.example.timfinprototypeback.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.timfinprototypeback.entity.stock;
import com.example.timfinprototypeback.service.stockService;
import com.example.timfinprototypeback.service.stockServiceImpl;
import com.example.timfinprototypeback.utils.netManger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/stock")
public class stockController {
    @Autowired
    private stockService myStockService;
    netManger myNet = new netManger();

    @RequestMapping(value = "/findStock", method = RequestMethod.GET)
    public stock findStock(@RequestBody(required = false) JSONObject info) {
        String queryStock = new String("");
        String queryDate = new String("");
        stock myStock;

        try {
            queryStock = (String) info.get("tscode");
            queryDate = (String) info.get("tradeDate");
            myStock = myStockService.findStock(queryStock);
            if (myStock.getTradedate() != queryDate)
                throw new Exception();
        } catch (Exception e1) {
            myStock = myStockService.findStock("000065");;
        }

        return myStock;
    }

    @RequestMapping(value="/predict", method = RequestMethod.GET)
    public String predict(@RequestBody(required = false) JSONObject info) {
        try {
            return myNet.rnnRun();
        } catch (Exception e1) {
            System.out.println("predict sth wrong");
            return null;
        }
    }

    /*@RequestMapping(value = "/test1", method = RequestMethod.GET)
    public stock yes(@RequestBody(required = true) JSONObject info) {
       return myStockService.findStock(info.get("tscode").toString());
    }*/
}
